import { type ClassValue, clsx } from "clsx"
import { twMerge } from "tailwind-merge"

export function cn(...inputs: ClassValue[]) {
  return twMerge(clsx(inputs))
}

export function formatCurrency(value: number, currency: string = 'USD') {
  return new Intl.NumberFormat('en-US', {
    style: 'currency',
    currency,
    minimumFractionDigits: 2,
    maximumFractionDigits: 2
  }).format(value)
}

export function formatNumber(value: number) {
  if (value >= 1e9) {
    return (value / 1e9).toFixed(2) + 'B'
  }
  if (value >= 1e6) {
    return (value / 1e6).toFixed(2) + 'M'
  }
  if (value >= 1e3) {
    return (value / 1e3).toFixed(2) + 'K'
  }
  return value.toString()
}

export function formatPercentage(value: number) {
  return `${value >= 0 ? '+' : ''}${value.toFixed(2)}%`
}

export function formatTimeframe(timeframe: string) {
  const map: Record<string, string> = {
    '1m': '1 Minute',
    '5m': '5 Minutes',
    '15m': '15 Minutes',
    '1h': '1 Hour',
    '4h': '4 Hours',
    '1d': '1 Day',
    '1w': '1 Week',
    '1M': '1 Month'
  }
  return map[timeframe] || timeframe
}
